package com.zjs.jsp.fdservice.messagelistener;


import com.currencyboot.service.rocketmq.messagelistener.Interface.MqExceedCountInterface;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zjs.jsp.domain.axd.Jsp_axd_order;
import com.zjs.jsp.domain.jsp.Jsp_ExceptionOrder;
import com.zjs.jsp.domain.jsp.Jsp_Order;
import com.zjs.jsp.fdservice.service.mongodb.ExceptionOrderExpand;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.common.message.MessageExt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
* <p>Title: MqExceedCount </p>
* <p>@Description: 超出失败次数的处理 </p>
* <p>Company:  </p>
* @author 李文
* @date   2016年9月22日 下午3:28:54 
*/
public class MqExceedCount implements MqExceedCountInterface
{

	private static final Logger LOGGER= LoggerFactory.getLogger(MqExceedCount.class);

	private static final ObjectMapper JSON_MAPPER = new ObjectMapper();

    @Autowired
    private ExceptionOrderExpand exoExpand;

	@Override
	public void exceedCount(String strBody, MessageExt msg, ConsumeConcurrentlyContext context)
	{

		try {
			Jsp_axd_order order = JSON_MAPPER.readValue(strBody, Jsp_axd_order.class);
			LOGGER.info(order.getId()+" 超出容错次数 ");
            Jsp_Order jspOrder = order.toJspOrder();
            exoExpand.saveEx(jspOrder, null, "超出容错次数 数据是： " + strBody, 7, "超出容错次数 ");

        } catch (Exception e) {
			LOGGER.error("  分单服务   超出容错次数  解析 客户订单 MQ 数据异常  数据是： " + strBody, e);
			Jsp_ExceptionOrder zxpExceptionOrder = new Jsp_ExceptionOrder("分单服务 解析 MQ 数据异常", strBody, 8);
            exoExpand.save(zxpExceptionOrder);
		}


	}

}
